<?php
namespace Club\Controller;
use Think\Controller;

class CourseController extends PublicController {
    public function courselist(){
    	$course=M('course');
        $id=$_SESSION['club'];
    	$course=$course->where("club=$id")->join('club ON club.clubid=course.club')->select();
    	$this->assign("course",$course);
        $this->display();
    }
    //添加课程：王子恒
    public function add(){
        $course = M('course');
        if($course->create()){
            $course->club=$_SESSION['club'];
            if (false !== $course->add()) {
                $this->success('添加成功！', U('courselist'));
            } else {         
                $this->error('数据错误','');           
            }
        }else {            
            $this->error($course->getError());  
        }
    }
    //删除课程：王子恒
    public function delete(){
        $id=$_GET['courseid'];
        $course=M('course');
        $course=$course->where("courseid=$id")->delete();
        if($course=1){
            $this -> success('删除成功！','');
        }else{
            $this->error('删除失败！','');
        }
    }
    //编辑课程：王子恒
    public function editcourse(){
        $id=$_GET['courseid'];
        $course=M('course');
        $course =$course->where("courseid=$id")->find();
        $this->assign('course',$course);
        $this->display();
    }
    //修改课程：王子恒
    public function edit(){
        $id=$_GET['courseid'];
        $course=M('course');
        $course->create();
        $course->club=$_SESSION['club'];
        $course->where("courseid=$id")->save(); 
        if ($course=1) {
                $this->success('修改成功！', U('courselist'));
            } else {         
                $this->error('修改错误','');           
            }
    }


}

